<?php
/**
 * 核心文件
 * 处理
 *  参数
 *  请求
 *  业务转发
 *  输出
 * 
 * @package ews
 * @ews Enterprise WorkShop
 * @version 1.0 alpha
 * @since 2011-05-16
 * @author monkee
 */
 class template
 {
 	static function parse($file){
 		$file_path = ROOT.DIR_TMP.$file.'.htm';
 		if(!is_file($file_path)){
 			return -1;
 		}
 		$content = file_get_contents($file_path);
 		//<include path='' />
 		preg_match_all('|<include\s+path=[\'"]([a-z\/0-9\-]+)[\'"]\s*\/>|i', $content, $matches, PREG_SET_ORDER);
 		if(is_array($matches)){
 			$from = $to = array();
 			foreach($matches as $item){
 				$_t = template::parse($item[1]);
 				if($_t !== -1){
 					$from[] = $item[0];
 					$to[] = $_t;
 				}else{
 					exit("Template file [{$item[1]}] not exist!");
 				}
 			}
 			$content = str_replace($from, $to, $content);
 		}
 		return $content;
 	}
 }
 ?>